<?php
	require_once("../functions.php");
	if(!isLoggedIn()){
		header("location:index.php?message=".urlencode("Please login first."));
		die();
	}
	
	$con = connectToDB();
	
	$sql = "delete from user  where username='$_SESSION[username]' and password='$_SESSION[password]'";
	$result = mysql_query($sql, $con);
	if (!$result) {
		echo mysql_error() . "<br />" . $sql;
		die();
	}
	
	$nrows = mysql_affected_rows($con);
	$info = get_mysql_info();
	
	if($info["rows_matched"]==1 || $nrows==1){
		echo '<br /><p class="center" style="color:green;font-weight:bold">You have successfully deleted your account. Click <a href="logout.php">here</a> to finish.</p>';
	}else if($nrows>1){
		header("location:index.php",true);
		echo '<br /><p class="center" style="color:red;font-weight:bold">Other user accounts deleted. Click <a href="logout.php">here</a> to finish.</p>';
	}else{
		echo '<br /><p class="center" style="color:red;font-weight:bold">Delete unsuccessful.</p>';
	}
	
	unset($_SESSION['username']);
	unset($_SESSION['password']);
?>